package cn.iocoder.lw.module.core.enums.evaluation;

import lombok.Getter;

/**
 * 评价等级枚举
 *
 * @author Lw源码
 */
@Getter
public enum EvaluationLevelEnum {

    /**
     * 非常不满意
     */
    VERY_UNSATISFIED(1, "非常不满意"),

    /**
     * 不满意
     */
    UNSATISFIED(2, "不满意"),

    /**
     * 一般
     */
    AVERAGE(3, "一般"),

    /**
     * 满意
     */
    SATISFIED(4, "满意"),

    /**
     * 非常满意
     */
    VERY_SATISFIED(5, "非常满意");

    /**
     * 等级值
     */
    private final Integer level;

    /**
     * 等级名称
     */
    private final String name;

    EvaluationLevelEnum(Integer level, String name) {
        this.level = level;
        this.name = name;
    }

    /**
     * 根据等级值获取枚举
     *
     * @param level 等级值
     * @return 枚举
     */
    public static EvaluationLevelEnum getByLevel(Integer level) {
        if (level == null) {
            return null;
        }
        for (EvaluationLevelEnum evaluationLevel : values()) {
            if (evaluationLevel.getLevel().equals(level)) {
                return evaluationLevel;
            }
        }
        return null;
    }

    /**
     * 根据评分获取评价等级
     *
     * @param score 平均分
     * @return 评价等级
     */
    public static EvaluationLevelEnum getByScore(Double score) {
        if (score == null) {
            return null;
        }
        if (score >= 4.5) {
            return VERY_SATISFIED;
        } else if (score >= 3.5) {
            return SATISFIED;
        } else if (score >= 2.5) {
            return AVERAGE;
        } else if (score >= 1.5) {
            return UNSATISFIED;
        } else {
            return VERY_UNSATISFIED;
        }
    }

}